package vn.edu.ptithcm.pim.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import vn.edu.ptithcm.pim.dom.News;

public class NewsValidator implements Validator {

	public boolean supports(@SuppressWarnings("rawtypes") Class clazz) {
		return News.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title",
				"warning.required.news.title");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "type",
				"warning.required.news.type");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "content",
				"warning.required.news.content");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description",
				"warning.required.news.description");
	}

}
